package danran.rpc.common.service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Classname CacheItem
 * @Description TODO
 * @Date 2021/9/26 13:29
 * @Created by ASUS
 * <p>
 * 一个服务对应一个CacheItem
 */
public class CacheItem {
    /**
     * 服务列表
     */
    private List<Service> serviceList;
    /**
     * 集群中四个服务负载参数权重
     */
    private List<double[]> a;
    /**
     * 集群中每个机器的性能指标参数
     */
    private List<double[]> w_var;
    /**
     * 服务对应的权重
     */
    private List<Double> W;


    /**
     * 根据服务列表构造缓存项
     */
    public CacheItem(List<Service> serviceList) {
        this.serviceList = serviceList;
        this.a = new ArrayList<>(serviceList.size());
        this.w_var = new ArrayList<>(serviceList.size());
        for (int i = 0; i < serviceList.size(); i++) {
            a.add(new double[]{0.25, 0.25, 0.25, 0.25});
            w_var.add(new double[]{0.25, 0.25, 0.25, 0.25});
        }
        this.W = new ArrayList<>();
        for (int i = 0; i < serviceList.size(); i++) {
            W.add(1 / (serviceList.size() * 1.0));
        }
    }

    public int size() {
        return this.serviceList.size();
    }

    public List<double[]> getW_var() {
        return w_var;
    }

    public void setW_var(List<double[]> w_var) {
        this.w_var = w_var;
    }

    public List<Service> getServiceList() {
        return serviceList;
    }

    public void setServiceList(List<Service> serviceList) {
        this.serviceList = serviceList;
    }

    public List<double[]> getA() {
        return a;
    }

    public void setA(List<double[]> a) {
        this.a = a;
    }

    public List<Double> getW() {
        return W;
    }

    public void setL(List<Double> w) {
        this.W = w;
    }
}
